Object.defineProperty(exports, "__esModule", {
    value: !0
}), exports.default = void 0;

var request = _interopRequireWildcard(require("../../utils/request"));

function _interopRequireWildcard(e) {
    if (e && e.__esModule) return e;
    var t = {};
    if (null != e) for (var a in e) if (Object.prototype.hasOwnProperty.call(e, a)) {
        var r = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(e, a) : {};
        r.get || r.set ? Object.defineProperty(t, a, r) : t[a] = e[a];
    }
    return t.default = e, t;
}

var app = getApp(), CHOOSE_IMAGE_MAX_COUNT = 9, _default = {
    initImageData: function() {
        this.setData({
            CHOOSE_IMAGE_MAX_COUNT: CHOOSE_IMAGE_MAX_COUNT,
            remarkImages: [],
            remarkImagesTempPath: []
        });
    },
    removedExistsImagesIds: [],
    chooseUploadImage: function(e, t) {
        var a = this, r = this.data.remarkImagesTempPath.length, s = this.data.remarkImages.length, i = CHOOSE_IMAGE_MAX_COUNT - r - s;
        wx.chooseImage({
            count: i,
            sizeType: [ "compressed" ],
            success: function(e) {
                a.setData({
                    remarkImagesTempPath: a.data.remarkImagesTempPath.concat(e.tempFilePaths)
                }), t && t();
            }
        });
    },
    removeExistsImage: function(e) {
        var t = e.currentTarget.dataset.index, a = this.data.remarkImages.splice(t, 1);
        this.removedExistsImagesIds.push(a[0].id), this.setData({
            remarkImages: this.data.remarkImages
        });
    },
    removeTempImage: function(e) {
        var t = e.currentTarget.dataset.index;
        this.data.remarkImagesTempPath.splice(t, 1), this.setData({
            remarkImagesTempPath: this.data.remarkImagesTempPath
        });
    },
    previewRemarkImage: function(e) {
        var t = e.currentTarget.id, a = this.data.remarkImages.map(function(e) {
            return e.src;
        }).concat(this.data.remarkImagesTempPath);
        wx.previewImage({
            current: t,
            urls: a
        });
    },
    uploadRemarkImages: function(i, n) {
        n.noLoading || wx.showLoading({
            title: "上传图片中...",
            mask: !0
        });
        var m = i.length, o = 0;
        return new Promise(function(r) {
            var s = [];
            app.getTokens(function(a) {
                !function e(t) {
                    request.upload({
                        url: "".concat(n.url, "?accesstoken=").concat(a.accesstoken),
                        name: n.name || "file",
                        filePath: t,
                        formData: n.data
                    }).then(function(e) {
                        return s.push(e), Promise.reject();
                    }).catch(function() {
                        ++o === m ? r(s) : e(i[o]);
                    });
                }(i[o]);
            });
        });
    }
};

exports.default = _default;